package com.duobaoyu.dby.supply.biz.converter;

import com.duobaoyu.dby.channel.boundary.bean.message.param.QueryMessageParam;
import com.duobaoyu.dby.channel.boundary.bean.message.param.RemoveMessageParam;
import com.duobaoyu.dby.channel.boundary.bean.message.result.QueryMessageResult;
import com.duobaoyu.dby.channel.boundary.bean.message.result.RemoveMessageResult;
import com.duobaoyu.dby.channel.strategy.bean.MessagePull;
import com.duobaoyu.dby.channel.strategy.bean.MessagePullResult;
import com.duobaoyu.dby.common.core.constant.CommonConstants;
import com.duobaoyu.dby.common.core.convert.bean.ReferenceMapper;
import com.duobaoyu.dby.supply.biz.client.boundary.message.bean.bo.MessagePullBO;
import com.duobaoyu.dby.supply.biz.client.boundary.message.bean.bo.QueryMessageBO;
import com.duobaoyu.dby.supply.biz.client.boundary.message.bean.bo.RemoveMessageBO;
import com.duobaoyu.dby.supply.biz.client.boundary.message.bean.dto.MessagePullDTO;
import com.duobaoyu.dby.supply.biz.client.boundary.message.bean.dto.QueryMessageDTO;
import com.duobaoyu.dby.supply.biz.client.boundary.message.bean.dto.RemoveMessageDTO;
import com.duobaoyu.dby.supply.common.biz.bo.message.ChannelMessageBO;
import com.duobaoyu.dby.supply.core.common.util.DeflaterUtils;
import com.duobaoyu.dby.supply.db.entity.message.ChannelMessage;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.Builder;
import org.mapstruct.Mapper;

/**
 * @author liyang
 * @version 1.0.0
 * @ClassName ChannelMessageConverter
 * @Description 渠道消息转换
 * @createTime 15:21:00 2023/09/28
 */
@Mapper(uses = {ReferenceMapper.class}, builder = @Builder(disableBuilder = true), componentModel = CommonConstants.COMPONENT_MODEL)
public interface ChannelMessageConverter {

	default ChannelMessageBO toChannelMessage(ChannelMessage channelMessage) {
		return ChannelMessageBO.builder()
				.channelMessageId(channelMessage.getId())
				.channelCode(channelMessage.getChannelCode())
				.configUniqueKey(channelMessage.getConfigUniqueKey())
				.originalMessage(StringUtils.isBlank(channelMessage.getOriginalMessage()) ? null : DeflaterUtils.unzipString(channelMessage.getOriginalMessage()))
				.uniqueKey(channelMessage.getUniqueKey())
				.messageType(channelMessage.getMessageType())
				.message(StringUtils.isBlank(channelMessage.getMessage()) ? null : DeflaterUtils.unzipString(channelMessage.getMessage()))
				.isBatch(channelMessage.getIsBatch())
				.retryCount(channelMessage.getRetryCount())
				.status(channelMessage.getStatus())
				.operationalCode(channelMessage.getOperationalCode())
				.channelOperationalCode(channelMessage.getChannelOperationalCode())
				.version(channelMessage.getVersion())
				.createTime(channelMessage.getCreateTime())
				.updateTime(channelMessage.getUpdateTime())
				.build();
	}

	/**
	 * to QueryMessageParam
	 * @param queryMessage
	 * @return
	 */
    QueryMessageParam toQueryMessageParam(QueryMessageDTO queryMessage);

	/**
	 * to QueryMessageBO
	 * @param queryMessageResult
	 * @return
	 */
	QueryMessageBO toQueryMessage(QueryMessageResult queryMessageResult);

	/**
	 * to RemoveMessageParam
	 * @param removeMessage
	 * @return
	 */
	RemoveMessageParam toRemoveMessageParam(RemoveMessageDTO removeMessage);

	/**
	 * to RemoveMessageBO
	 * @param removeMessageResult
	 * @return
	 */
	RemoveMessageBO toRemoveMessage(RemoveMessageResult removeMessageResult);

	/**
	 * to MessagePull
	 * @param messagePull
	 * @return
	 */
	MessagePull toMessagePull(MessagePullDTO messagePull);

	/**
	 * to MessagePullBO
	 * @param messagePullResult
	 * @return
	 */
	MessagePullBO toMessagePull(MessagePullResult messagePullResult);
}
